<template>
  <div class="home-list">
    <div
      class="home-item"
      v-for="item of dataList"
      :key="item.bgColor"
      :style="{ backgroundColor: item.bgColor }"
    >
      <i :class="classFn(item.iconClass)"></i>
      <span class="item-des">{{ item.des }}</span>
      <span class="item-number">{{ dataObj[item.key] }}{{ item.unit }}</span>
    </div>
  </div>
</template>

<script>
import { getHomeIndex } from "@/api";
export default {
  name: "HomeList",
  data() {
    return {
      dataList: [
        {
          bgColor: "#48C8B1",
          des: "已上传产品数",
          iconClass: "el-icon-upload",
          key: "prtUseCount",
          unit: "款"
        },
        {
          bgColor: "#FE9901",
          des: "剩余上传产品数",
          iconClass: "el-icon-upload",
          key: "prtCount",
          unit: "款"
        },
        {
          bgColor: "#E84C3D",
          des: "已使用流量",
          iconClass: "el-icon-odometer",
          key: "flUseCount",
          unit: "G"
        },
        {
          bgColor: "#7C55CA",
          des: "剩余流量",
          iconClass: "el-icon-odometer",
          key: "flCount",
          unit: "G"
        },
        {
          bgColor: "#4A8FD4",
          des: "年访问量",
          iconClass: "el-icon-view",
          key: "yearCount",
          unit: "次"
        },
        {
          bgColor: "#349CAB",
          des: "月访问量",
          iconClass: "el-icon-view",
          key: "monthCount",
          unit: "次"
        },
        {
          bgColor: "#BA3DE8",
          des: "日访问量",
          iconClass: "el-icon-view",
          key: "dayCount",
          unit: "次"
        },
        {
          bgColor: "#5E0AB5",
          des: "总访问量",
          iconClass: "el-icon-view",
          key: "allCount",
          unit: "次"
        }
      ],
      dataObj: {}
    };
  },

  created() {
    this.initData();
  },

  methods: {
    async initData() {
      console.log(this.$store.state.user.shopUuid);
      const params = {
        uuid: this.$store.state.user.shopUuid
      };
      let res = await getHomeIndex(params).catch(err => console.log(err));
      if (!res) return;
      this.dataObj = res.items;
    },
    classFn(name) {
      return name;
    }
  }
};
</script>

<style lang="scss" scoped>
.home-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  .home-item {
    margin: 20px;
    width: 351px;
    height: 353px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    & > i {
      font-size: 152px;
      color: #a4e4d8;
    }

    .item-des {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
      margin: 42px 0 18px;
    }

    .item-number {
      font-size: 30px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #ffffff;
    }
  }
}
</style>
